/*
* 2010
* Author: Kuznetsov Kirill<kirill.kuznets@gmail.com>
* i/o functions
*/
#include "stdafx.h"

#include <boost/graph/graphviz.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/properties.hpp>
#include <conio.h>

using namespace boost;
using namespace std;


bool fas_read(const string &filename, Graph & worker)
{
	// Construct an empty graph and prepare the dynamic_property_maps.
	cout << "Reading..." << endl; 
	dynamic_properties dp;

	property_map<Graph, vertex_name_t>::type name = get(vertex_name, worker);
	dp.property("node_id", name);

	property_map<Graph, vertex_index_t>::type index = get(vertex_index, worker);
	dp.property("vertex_idx", index);

	ifstream ifile(filename.c_str());

	if (!ifile)
	{
		cerr << "Error: can't open input file." << endl;
		ifile.close();
		return false;
	}
	// warning
	bool status = read_graphviz(ifile, worker, dp, "node_id");
	if (!status)
	{
		cout << "Error: can't read graph file.";
		return false;
	}
	ifile.close();
	return true;
}

void fas_write(const string &filename, const Graph &worker)
{
	ofstream out;
	out.open(filename.c_str());
	write_graphviz(out, worker);
	out.close();    
}

void print_log ( string log_msg){ 
	#ifdef _DEBUG
        cout << log_msg; 
	#endif	
}